package com.atguigu.flink.datastramapi.transform;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created by Smexy on 2023/2/25
 */
public class Demo3_Filter
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        DataStreamSource<Integer> ds = env.fromElements(1, 2, 3, 4, 5, 6);

        //过滤奇数
        //留下返回true  可以分流
        SingleOutputStreamOperator<Integer> ds1 = ds.filter(value -> value % 2 == 1);
        SingleOutputStreamOperator<Integer> ds2 = ds.filter(value -> value % 2 == 0);

        ds1.map(x -> x + 10).print("奇数流");
        ds2.map(x -> x + 100).printToErr("偶数流");


        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
